//
//  RepairScheduleView.m
//  CirclePlay
//
//  Created by mac on 16/11/3.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "RepairScheduleView.h"
@interface RepairScheduleView()

@property(nonatomic,assign)CGFloat width;

@end
@implementation RepairScheduleView

-(instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        self.width=frame.size.width/7;
    }
    return self;
}
-(instancetype)init{
    self=[super init];
    if (self) {
        self.backgroundColor=[UIColor clearColor];
    }
    
    return self;
}
-(void)awakeFromNib{
    [super awakeFromNib];
    self.backgroundColor=[UIColor clearColor];
}
-(void)setShcedulenNum:(NSInteger)shcedulenNum{
    _shcedulenNum=shcedulenNum;
    [self setNeedsDisplay];
}
-(void)drawRect:(CGRect)rect{
    CGFloat radiu=5.;
    CGFloat width=rect.size.width/7.;
    CGContextRef ctx=UIGraphicsGetCurrentContext();
    CGFloat start=rect.origin.x+width/2.;
    for (int i=0; i<7; i++) {
        //        CGContextSaveGState(ctx);
        UIColor *arcColor;
        if (i<self.shcedulenNum) {
            arcColor=[UIColor colorWithRed:155/255. green:226/255. blue:141/255. alpha:1.0];
            if (!self.isReception) {
                //没有接车圆点变灰
                if (i==1) {
                    arcColor=[UIColor colorWithRed:204/255. green:204/255. blue:204/255. alpha:1.0];
                }
            }
        }else{
            if (i==self.shcedulenNum) {
                arcColor=[UIColor clearColor];
            }else
                arcColor=[UIColor colorWithRed:204/255. green:204/255. blue:204/255. alpha:1.0];
        }
        if (self.hideFirst) {
            if (i==0) {
                
                arcColor=[UIColor clearColor];
            }
        }
        CGContextSetLineWidth(ctx, 2);
        CGContextSetStrokeColorWithColor(ctx, arcColor.CGColor);
        CGContextAddArc(ctx, start+i*width, rect.size.height/2., radiu, 0, 2*M_PI, YES);
        CGContextDrawPath(ctx, kCGPathStroke);
        //        CGContextRestoreGState(ctx);
        if (i<6) {
            UIColor *lineColor=[UIColor lightGrayColor];
            if (self.hideFirst) {
                if (i==0) {
                    
                    lineColor=[UIColor clearColor];
                }
            }
            
            CGContextSetStrokeColorWithColor(ctx, lineColor.CGColor);
            CGContextSetLineWidth(ctx, 3);
            if (i==self.shcedulenNum-1) {
                
                CGContextMoveToPoint(ctx, start+i*width+radiu, rect.size.height/2.);//设置Path的起点
                CGContextAddLineToPoint(ctx, start+(i+1)*width-34, rect.size.height/2);
                
            }
            else if (i==self.shcedulenNum) {
                
                CGContextMoveToPoint(ctx, start+i*width+34, rect.size.height/2.);//设置Path的起点
                CGContextAddLineToPoint(ctx, start+(i+1)*width-radiu,rect.size.height/2);
            }
            else{
                CGContextMoveToPoint(ctx, start+i*width+radiu, rect.size.height/2.);//设置Path的起点
                CGContextAddLineToPoint(ctx, start+(i+1)*width-radiu, rect.size.height/2);
            }
            CGContextStrokePath(ctx);//
        }
        
        
    }
}

@end
